<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../estilos/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	function search() {
		if (document.searchForm.razonSocialAbuscar.value != ''
				|| document.searchForm.cuitAbuscar.value != ''
				|| document.searchForm.responsableAbuscar.value != '') {

			document.searchForm.typeModif.value = 'filter';
			document.searchForm.returnAction.value = 'modificacion';
			document.searchForm.submit();
		}
	}
	function updateCli(codCliente, razonSocial, cuit, responsable, domicilio,
			localidad, codigoPostal, provincia, telefono, fax, email) {
		document.modificarForm.codCliente.value = codCliente;
		document.modificarForm.razonSocial.value = razonSocial;
		document.modificarForm.cuit.value = cuit;
		document.modificarForm.responsable.value = responsable;
		document.modificarForm.domicilio.value = domicilio;
		document.modificarForm.localidad.value = localidad;
		document.modificarForm.codigoPostal.value = codigoPostal;
		document.modificarForm.provincia.value = provincia;
		document.modificarForm.telefono.value = telefono;
		document.modificarForm.fax.value = fax;
		document.modificarForm.email.value = email;
	}

	function save() {

		var cuit = $.trim(document.modificarForm.cuit.value);

		if (cuit != '') {
			document.modificarForm.cuit.disabled = false;
			document.modificarForm.razonSocial.disabled = false;
			document.modificarForm.typeModif.value = 'update';
			document.modificarForm.submit();
		} else {
			alert("Debe seleccionar un cliente a modificar.");
		}
	}

	function cancel() {
		document.modificarForm.action = 'listarClientesAction';
		document.modificarForm.submit();
	}

	function verificarBusquedaCliente() {
		if (document.searchForm.clienteNoEncontrado.value == 'true') {
			alert("No se ha encontrado un cliente con esos datos de búsqueda. Por favor intente nuevamente.");
		}
	}
</script>
<title>LABTEC - Actualizar Cliente</title>
</head>
<body onload="verificarBusquedaCliente()">
	<div id="header">
		    <jsp:include page="../jsp/menuIniciador.jsp" />
	</div>
	<div class="sheet">
		<div class="sheet-tl"></div>
		<div class="sheet-tr"></div>
		<div class="sheet-bl"></div>
		<div class="sheet-br"></div>
		<div class="sheet-tc"></div>
		<div class="sheet-bc"></div>
		<div class="sheet-cl"></div>
		<div class="sheet-cr"></div>
		<div class="sheet-cc"></div>
		<div class="sheet-body">
			<br />
			<h5 class="postcontent">Buscar datos del Cliente</h5>
			<br />
			<s:form action="filtrarClientesAction" theme="simple" id="searchForm">
				<s:hidden name="typeModif" />
				<s:hidden name="returnAction" />
				<s:hidden name="clienteNoEncontrado" />
				<table width="100%">
					<tr>
						<td width="15%">Razón Social</td>
						<td width="20%"><input type="text" name="razonSocialAbuscar"
							id="razonSocialAbuscar" /></td>
						<td width="15%">CUIT</td>
						<td width="20%"><input type="text" name="cuitAbuscar"
							id="cuitAbuscar" /></td>
						<td width="15%">Responsable</td>
						<td width="15%"><input type="text" name="responsableAbuscar"
							id="responsableAbuscar" /></td>
						<td width="35%" align="left"><input type="button"
							value="Buscar" onclick="search()" /></td>
					</tr>
				</table>
			</s:form>
			<br>
			<div style="height: 250px; width: 1175px; overflow: scroll;"
				align="center">
				<table class="article">
					<thead>
						<tr>
							<th>Razón Social</th>
							<th>Responsable</th>
							<th>CUIT</th>
							<th>Domicilio</th>
							<th>Localidad</th>
							<th>Código Postal</th>
							<th>Provincia</th>
							<th>Teléfono</th>
							<th>Fax</th>
							<th>Email</th>
							<th>Modificar</th>
						</tr>
					</thead>

					<tbody>
						<s:iterator value="listClientes">
							<tr>
								<s:hidden value="codCliente"></s:hidden>
								<td width="10%"><s:property value="razonSocial" /></td>
								<td width="10%"><s:property value="responsable" /></td>
								<td width="11%"><s:property value="cuit" /></td>
								<td width="15%"><s:property value="domicilio" /></td>
								<td width="10%"><s:property value="localidad" /></td>
								<td width="5%"><s:property value="codigoPostal" /></td>
								<td width="10%"><s:property value="provincia" /></td>
								<td width="8%"><s:property value="telefono" /></td>
								<td width="8%"><s:property value="fax" /></td>
								<td width="8%"><s:property value="email" /></td>
								<td width="5%"><input type="button" value="Modificar"
									onclick="updateCli('<s:property value="codCliente"/>',
																								'<s:property value="razonSocial"/>',
																								'<s:property value="cuit"/>',
																								'<s:property value="responsable"/>',
																								'<s:property value="domicilio"/>',
																								'<s:property value="localidad"/>',
																								'<s:property value="codigoPostal"/>',
																								'<s:property value="provincia"/>',
																								'<s:property value="telefono"/>',
																								'<s:property value="fax"/>',
																								'<s:property value="email"/>')">
								</td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</div>
			<br>
			<s:if test="hasFieldErrors()">
				<div class="error">
					<s:fielderror />
				</div>
			</s:if>
			<s:if test="hasActionErrors()">
				<div class="error">
					<s:actionerror />
				</div>
			</s:if>
			<br>
			<div class="postmetadataheader">
				<s:form action="modificarClienteAction" theme="simple"
					id="modificarForm" validate="true">
					<h5 class="postcontent">Modificar datos del Cliente</h5>
					<br>
					<s:hidden name="typeModif"></s:hidden>
					<s:hidden name="codCliente"></s:hidden>
					<table width="100%">
						<tr>
							<td width="15%">Razón Social</td>
							<td width="45%"><s:textfield name="razonSocial"
									id="razonSocial" disabled="true" required="true" maxlength="30"></s:textfield></td>
							<td width="15%">CUIT</td>
							<td width="45%"><s:textfield name="cuit" disabled="true"
									id="cuit" maxlength="11"></s:textfield></td>
						</tr>
						<tr>
							<td>Responsable</td>
							<td><s:textfield name="responsable" maxlength="20" /></td>
							<td>Domicilio</td>
							<td><s:textfield name="domicilio" maxlength="40" /></td>
						</tr>
						<tr>
							<td>Localidad</td>
							<td><s:textfield name="localidad" maxlength="30"></s:textfield></td>
							<td>Código Postal</td>
							<td><s:textfield name="codigoPostal" maxlength="10"></s:textfield></td>
						</tr>
						<tr>
							<td>Provincia</td>
							<td><s:textfield name="provincia" maxlength="20"></s:textfield></td>
							<td>Teléfono</td>
							<td><s:textfield name="telefono" maxlength="20"></s:textfield></td>
						</tr>
						<tr>
							<td>Fax</td>
							<td><s:textfield name="fax" maxlength="20"></s:textfield></td>
							<td>Email</td>
							<td><s:textfield name="email" maxlength="40"></s:textfield></td>
						</tr>
						<tr align="right" height="70px">
							<td colspan="4"><input type="button" value="Guardar"
								onclick="save();" /></td>
						</tr>
					</table>
				</s:form>
			</div>
			<p>&nbsp;</p>

		</div>
	</div>
</body>
</html>